{template 'common/header'}
{template 'web/common'}
<style type="text/css">
    .tooltipbox {
        background: #f8f8f8;
         border: 1px solid #f8f8f8;
        color: #f8f8f8;
    }
</style>
<!-- 编辑器源码文件 -->
<!--<script type="text/javascript" src="/addons/goouc_class/library/TextEdit/ueditor.config.js"></script>
<script type="text/javascript" src="/addons/goouc_class/library/TextEdit/ueditor.all.js"></script>
<script type="text/javascript" charset="utf-8" src="/addons/goouc_class/library/TextEdit/kityformula-plugin/addKityFormulaDialog.js"></script>
<script type="text/javascript" charset="utf-8" src="/addons/goouc_class/library/TextEdit/kityformula-plugin/getKfContent.js"></script>
<script type="text/javascript" charset="utf-8" src="/addons/goouc_class/library/TextEdit/kityformula-plugin/defaultFilterFix.js"></script>-->
<!-- 编辑器源码文件 -->
<ul class="nav nav-tabs">
    <li {if $op == 'list'}class="active"{/if}>
    <a href="{php echo $this->createWebUrl('practice',array('op'=>'list','lid'=>$lid,'sonid'=>$sonid))}" >习题列表</a>
    </li>
    <li {if $op == 'edit'}class="active"{/if}>
    <a href="{php echo $this->createWebUrl('practice',array('op'=>'edit','lid'=>$lid,'sonid'=>$sonid))}" >{if empty($info['id'])}添加习题{else}修改习题信息{/if}</a>
    </li>
    <li {if $op == 'import'}class="active"{/if}>
    <a href="{php echo $this->createWebUrl('practice',array('op'=>'import','lid'=>$lid,'sonid'=>$sonid))}" >导入习题</a>
    </li>
</ul>

<form action="" class="form-horizontal form" id="data_from" method="post" enctype="multipart/form-data" onsubmit="return formcheck()">
    <input type="hidden" name="id" value="{$item['id']}">
    <div class="panel panel-default remd">
        <div class="panel-heading" style="background-color: #D9EDF7">
            习题编辑：{$lessontitle['title']}->{$sontitle['title']}
        </div>
        <div class="panel-body" style="margin: 0 150px 0 50px;">
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">题目类型</label>
                <div class="col-sm-9 col-xs-12">
                    <select class='form-control' id='qtype' name='type'>
                        <option value=''>--请选择题目类型--</option>
                        {loop $types_config $key $value}
                        <option id="option_{$key}" class="option_class" value ="{$key}" {if $item['type'] == $key}selected="selected"{/if}>{$value}</option>
                        {/loop}
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">题目问题</label>
                <div class="col-sm-9 col-xs-12">
                    <textarea style="height:100px;" id="question" name="question" class="form-control" cols="60">{$item['question']}</textarea>
                </div>
            </div>
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">题目图片</label>
                <div class="col-sm-9 col-xs-12">
                    {php echo tpl_form_field_image('thumb',$item['thumb']);}
                    <span class="help-block">图片建议宽度315像素，高度自适应</span>
                </div>
            </div>
            <div class="form-group"  id="answer_isimg" style="{if $item['type'] != 2 && $item['type'] != 3}display: none;{/if}">
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">答案类型</label>
                <div class="col-sm-9 col-xs-12">
                    <label class="radio-inline"><input type="radio" name="isimg" onclick="changeTo('text')" id='isimg' value="0" {if $item['isimg'] == 0} checked="true" {/if}>文本</label>&nbsp;&nbsp;
                    <label class="radio-inline"><input type="radio" name="isimg" onclick="changeTo('image')" value="1" {if $item['isimg'] == 1} checked="true" {/if}>图片</label>&nbsp;&nbsp;
                </div>
            </div>
            <div class="form-group item"  id="item_1"  style='{if $item['type'] !=1} display:none {/if}' >
                <label class="col-xs-12 col-sm-3 col-md-2 control-label">选项答案</label>
                <div class="col-sm-9 col-xs-12">
                    <label class="radio-inline">
                        <input type="radio" name="answer1" class='answer1' value="1" {if $item['answer']==1}checked{/if} />正确
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="answer1" class='answer1'  value="0" {if $item['answer']==0}checked{/if}/>错误
                    </label>
                </div>
            </div>
        <div class="form-group item"  id="item_2"  style='{if $item['type'] !=2}display:none{/if}' >
            <label class="col-xs-12 col-sm-3 col-md-2 control-label"> 单选题</label>
            <div class="col-sm-9 col-xs-12">
                <table class='table'>
                    {loop $answer_array $key $value}
                    <tr>
                        <td style='width:50px;' valign='top'>
                            <label class="radio-inline">
                                <input type="radio" name="answer2" class="answer2" value="{$value}" {if $item['answer'] == "$value"}checked{/if} />{$value}</label>
                        </td>
                        <td>
                            <input type='test' class='form-control items2' name='items2[]' value="{$item['items'][$key]['p']}"  need="{if $key < 3}true{else}false{/if}"/>
                            <div class="item-image" {if $item['isimg'] == 0}style="display:none;"{/if}>
                            {php echo tpl_form_field_image("img_items2_" . $key, $item['img_items'][$key]['p']);}
                            <span class="help-block">图片建议宽度262像素，高度自适应</span>
                            </div>
                        </td>
                    </tr>
                    {/loop}
                </table>
            </div>
        </div>
        <div class="form-group item" id="item_3" style='{if $item['type'] !=3}display:none{/if}'>
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">多选题</label>
            <div class="col-sm-9 col-xs-12">
                <table class='table'>
                    {loop $answer_array $key $value}
                    <tr>
                        <td style='width:50px;' valign='top'>
                            <label class="checkbox-inline">
                                <input type="checkbox" name="answer3[]" class="answer3"  value="{$value}" {if stripos($item['answer'], "$value") > -1}checked{/if} />{$value}
                            </label>
                        </td>
                        <td><input type='test' class='form-control items3' name='items3[]' value="{$item['items'][$key]['p']}" need="{if $key < 4}true{else}false{/if}"/>
                            <div class="item-image" {if $item['isimg'] == 0}style="display:none;"{/if}>
                            {php echo tpl_form_field_image("img_items3_" . $key, $item['img_items'][$key]);}
                            <span class="help-block">图片建议宽度262像素，高度自适应</span></div>
                        </td>
                    </tr>
                    {/loop}
                </table>
            </div>
        </div>

        <div class="form-group item"  id="item_4"  style='{if $item['type'] !=4}display:none{/if}' >
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">填空答案</label>
            <div class="col-sm-9 col-xs-12">
                <input type='test' class='form-control items4' name='items4' value="{$item['answer']}" />
                <span class="help-block">每空答案请用【】，如果有多个空，请用‘、’将答案分隔开,例：【1】、【2】、【3】</span>
            </div>
        </div>
    <div class="form-group" style="margin-top:25px">
        <label  class="col-sm-2 control-label">排序</label>
        <div class="col-sm-10">
            <input type="number" name="sort" value="{if empty($item['sort'])}0{else}{$item['sort']}{/if}"  class="form-control" style="width:98%" onfocus="this.value=''"/>
            <span class="help-block">数字越大排序越靠前</span>
        </div>
    </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-2 control-label">讲解</label>
            <div class="col-sm-9 col-xs-12">
                <textarea style="height:100px;" id="analysis" name="analysis" class="form-control" cols="60">{$item['analysis']}</textarea>
            </div>
        </div>
    </div>

    <div class="form-group col-sm-12">
        <button type="button" class="btn btn-primary span3" name="submitsave" onclick="submit_next(0)" value="提交">提交</button>
        {if $id == ''}
        <button type="button" class="btn btn-primary span3" name="submitnext" onclick="submit_next(1)" value="提交并添加下一题">提交并添加下一题</button>
        {/if}
        <input type="hidden" name="token" value="{$_W['token']}" />
        <input type="hidden" name="is_next" id="is_next" value="0" />
    </div>
</form>
<script type="text/javascript">
    function changeTo(t){
        if(t=='image'){
            $(".item-image").show();
            $(".items3").attr("type","hidden");
            $(".items2").attr("type","hidden");
            $(".items5").attr("type","hidden");
        }
        else{
            $(".item-image").hide();
            $(".items3").attr("type","text");
            $(".items2").attr("type","text");
            $(".items5").attr("type","text");
        }
    }
    //根据选项更改答案
    $(function(){
        $("#qtype").change(function(){
            var type = $(this).val();
            $(".item").hide();
            if(type!=''){
                $("#item_" + type).show();
            }
            if (type > 1 && type != 4 && type != 5) {
                $("#answer_isimg").show();
            } else {
                $("#answer_isimg").hide();
            }
        });
    });

    function submit_next(n){
        $("#is_next").val(n);
        $("#data_from").submit();
    }

    function item_check() {
        var isimg = $('input:radio[name="isimg"]:checked').val();
        var type = $("#qtype").val();
        var flag = 1;

        if (flag == 0) {
            return false;
        }

        if (type == '1') {
            var checked = false;
            $(".answer1").each(function () {
                if ($(this).get(0).checked) {
                    checked = true;
                    return false;
                }
            });
            if (!checked) {
                Tip.focus(".answer1:eq(0)", "", "top");
                $('.toast_div').toast({
                    content:'请选择正确答案!',
                    duration:1000
                });
                return false;
            }
        } else if (type == 2) {
            if (isimg == 0) {
                var ok = true;
                $(".items2").each(function () {
                    if ($(this).val() == '' && $(this).attr("need")=="true") {
                        Tip.focus($(this), "", "right");
                        $('.remd').toast({
                            content:'请填写选项!',
                            duration:1500
                        });
                        ok = false;
                        return false;
                    }
                });
                if (!ok) {
                    return false;
                }
            }

            var checked = false;
            $(".answer2").each(function () {
                if ($(this).get(0).checked) {
                    checked = true;
                    return false;
                }
            });
            if (!checked) {
                Tip.focus(".answer2:eq(0)", "", "top");
                $('.remd').toast({
                    content:'请选择一个答案!',
                    duration:1500
                });
                return false;
            }
        } else if (type == '3') {
            if (isimg == 0) {
                var ok = true;
                $(".items3").each(function () {
                    if ($(this).val() == '' && $(this).attr("need")=="true") {
                        Tip.focus($(this), "", "right");
                        $('.remd').toast({
                            content:'请填写选项!',
                            duration:1500
                        });
                        ok = false;
                        return false;
                    }
                });
                if (!ok) {
                    return false;
                }
            }

            var checked = false;
            $(".answer3").each(function () {
                if ($(this).get(0).checked) {
                    checked = true;
                    return false;
                }
            });
            if (!checked) {
                Tip.focus(".answer3:eq(0)", "", "top");
                $('.remd').toast({
                    content:'至少选择一个答案!',
                    duration:1500
                });
                return false;
            }
        } else if (type == '4') {
            if($(".items4").val().trim() == ''){
                Tip.focus('.items4', "", "left");
                $('.remd').toast({
                    content:'请填写答案',
                    duration:1500
                });
                return false;
            }
        }
        if ($("#analysis").val().trim() == '') {
            Tip.focus("#analysis", "", "left");
            $('.remd').toast({
                content:'请填写讲解!',
                duration:1500
            });
            return false;
        }
    }

    function formcheck(){
        if ($("#qtype").val().trim() == '') {
            Tip.focus('#qtype', "", "left");
            $('.remd').toast({
                content:'请选择题目类型',
                duration:1500
            });
            return false;
        }
        if ($("#question").val().trim() == '') {
            Tip.focus("#question", "", "left");
            $('.remd').toast({
                content:'请填写题目问题!',
                duration:1500
            });
            return false;
        }
        return item_check();
    }

</script>
<!--<script type="text/javascript">
    window.UEDITOR_HOME_URL = '/addons/goouc_class/library/TextEdit/';
    $(function(){
        var ue = UE.getEditor('myEditor2', {
            toolbars: [[
                'fullscreen', 'source', '|',
                'bold', 'italic', 'underline', '|', 'fontsize', '|', 'kityformula', 'preview'
            ]]
        });
        var ue = UE.getEditor('myEditor3', {
            toolbars: [[
                'fullscreen', 'source', '|',
                'bold', 'italic', 'underline', '|', 'fontsize', '|', 'kityformula', 'preview'
            ]]
        });
        for(let i = 0; i < 6; i++){
            let name = 'Editor_'+i
            console.log(name)
            var ue = UE.getEditor(name, {
                toolbars: [[
                    'fullscreen', 'source', '|',
                    'bold', 'italic', 'underline', '|', 'fontsize', '|', 'kityformula', 'preview'
                ]]
            });
        }
    });

</script>-->
{template 'common/footer'}
